package ex_from_web;

class Task implements Runnable {
    String name;
    int heldup;
    
    public Task (String name, int heldup) {
        this.name = name;
        this.heldup = heldup;
    }
    
    //code which will be executed when the thread has been started
    public void run() {
        try {
            System.out.println(name + " started!");
            Thread.sleep(heldup); //1 second pause...
            System.out.println(name + " finished!");
        }catch(InterruptedException  e) {
            System.out.println(name + " interrupted!");
        }
    }
}

public class more_threads {

    public static void main(String[] args) {
        //creating Thread objects
        Thread s1 = new Thread(new Task("1st",4000));
        Thread s2 = new Thread(new Task("2nd", 3000));
        Thread s3 = new Thread(new Task("3rd", 2000));
        Thread s4 = new Thread(new Task("4th", 1000));
        
        //launching threads
        s1.start();
        s2.start();
        s3.start();
        s4.start();
    }
}